package net.joint_painting.server.model;

import java.util.logging.Logger;

import javax.jdo.JDOObjectNotFoundException;
import javax.jdo.PersistenceManager;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.google.appengine.api.datastore.Text;

/**
 * @author CAM
 * @version $Revision: 1.0 $
 */
@PersistenceCapable
public class JointPaintingSurface {

    private static final Logger log = Logger
	    .getLogger(JointPaintingSurface.class.getName());

    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private String id;

    @Persistent
    private Text data = new Text("");

    /**
     * Method getSurface.
     * 
     * @param id
     *            String
     * 
     * @return Surface
     */
    public static JointPaintingSurface getSurface(String id) {
	PersistenceManager pm = PMF.get().getPersistenceManager();
	JointPaintingSurface temp = null;
	try {
	    temp = pm.getObjectById(JointPaintingSurface.class, id);
	} catch (JDOObjectNotFoundException e) {
	    temp = new JointPaintingSurface(id);
	} finally {
	    pm.close();
	}
	return temp;
    }

    /**
     * Method save.
     * 
     * @param surface
     *            Surface
     */
    public static void save(JointPaintingSurface surface) {
	PersistenceManager pm = PMF.get().getPersistenceManager();
	try {
	    pm.makePersistent(surface);
	} catch (Exception e) {
	    log.severe(e.getMessage());
	} finally {
	    pm.close();
	}
    }

    public JointPaintingSurface() {
    }

    /**
     * Constructor for Surface.
     * 
     * @param id
     *            String
     */
    public JointPaintingSurface(String id) {
	this.id = id;
    }

    /**
     * 
     * @return the lines
     */
    public String getData() {
	return data.getValue();
    }

    public void save() {
	save(this);
    }

    /**
     * 
     * @param data
     *            String
     */
    public void setData(String data) {
	this.data = new Text(data);
    }
}
